﻿using Avalonia;
using Avalonia.Media;
using KinonekoSoftware.ArkSpark.Documents.Primitives;
using KinonekoSoftware.ArkSpark.Runtimes.Presenters;

namespace KinonekoSoftware.ArkSpark.Runtimes.Presenters
{
    public class HeadingTextPresenter : DocumentElementPresenter<HeadingText>
    {
        private int       _fontSize;
        private FontStyle _fontStyle;

        public HeadingTextPresenter(HeadingText element) : base(element)
        {
            SetStyle(element.Level);
        }

        public void SetStyle(int level)
        {
            switch (level)
            {
                case 1:

                    FontSize  = 52;
                    FontStyle = FontStyle.Normal;
                    break;
                case 2:
                    
                    FontSize  = 44;
                    FontStyle = FontStyle.Normal;
                    break;
                
                case 3:
                    
                    FontSize  = 38;
                    FontStyle = FontStyle.Normal;
                    break;
                
                case 4:
                    
                    FontSize  = 32;
                    FontStyle = FontStyle.Normal;
                    break;
                case 5:
                    FontSize  = 26;
                    FontStyle = FontStyle.Normal;
                    break;
                case 6:
                    FontSize  = 20;
                    FontStyle = FontStyle.Normal;
                    break;
                default:
                    FontSize  = 16;
                    FontStyle = FontStyle.Normal;
                    break;
            }
        }

        public string Content
        {
            get => TargetElement.Content;
            set
            {
                TargetElement.Content = value;
                //
                // 报告已更改
                ElementUpdatedEventArgs.OnNext(Bus);
                RaiseUpdated();
            }
        }

        public int Level
        {
            get => TargetElement.Level;
            set
            {
                var level = TargetElement.Level = Math.Clamp(value, 1, 7);
                
                
                //
                // 报告已更改
                ElementUpdatedEventArgs.OnNext(Bus);
                SetStyle(level);
                RaiseUpdated();
            }
        }
        
        public FontStyle FontStyle
        {
            get => _fontStyle;
            set => SetValue(ref _fontStyle, value);
        }
        
        public int FontSize
        {
            get => _fontSize;
            set => SetValue(ref _fontSize, value);
        }
    }
}